"""
@Author : 合肥一元数智教育科技有限公司
@Date :  2025/5/27 8:49
@Description :
面向对象三大特征:
多态:
1.父类的引用指向子类的对象   多态建立在继承的基础上  没有继承就没有多态
2.不同的对象调用相同的方法，表现出不同的状态，称之为多态

作用:
  实现代码的解耦合

class  Aoo:
   pass

class Boo(Aoo):
    pass

Boo 子类   Aoo 父类
aoo = Aoo()
boo = Boo()

aoo:Aoo = Boo()
"""
"""
主人饲养宠物
面向对象:  抽取参与的主体
1.主人
2.宠物
3.食物
"""
class Aoo:
    pass


#  宠物类
class Animal:
    def __init__(self, color, name):
        self.color = color
        self.name = name

    def hoot(self):
        print('动物的叫声')


class Dog(Animal):

    def hoot(self):
        print('汪汪叫')

    pass


class Cat(Animal):
    def hoot(self):
        print('喵喵叫')

    pass


# 抽取食物
class Food:
    def __init__(self, name):
        self.name = name


class Bone(Food):
    pass


class Fish(Food):
    pass


class Master:
    """
        # 饲养猫
    def feed_cat(self, cat, fish):
        print(f'颜色是{cat.color}的{cat.name}正在吃{fish.name}')

    # 饲养狗
    def feed_dog(self, dog, bone):
        print(f'{dog.name}正在吃{bone.name}')

    """

    # 利用多态的思路 改写函数的设计
    def feed(self, animal: Animal, food: Food):
        print(f'颜色是{animal.color}的{animal.name}正在吃{food.name}')


if __name__ == '__main__':
    # cat: Cat = Cat('white','cat1' )
    # cat: Dog = Cat('white', 'cat1')  # 猫是狗
    cat: Animal = Cat('white', 'cat1')  # 猫是一个动物
    fish: Food = Fish('fish1')
    dog: Animal = Dog('black', 'dog1')
    bone: Food = Bone('bone1')
    print('---------------------------------------------')
    # 判定对象的类型
    print(f'cat: Cat = {isinstance(cat, Cat)}')
    print(f'cat: Animal = {isinstance(cat, Animal)}')

    # 创建主人对象
    master = Master()
    # aoo = Aoo()
    # master.feed(aoo, fish)

    master.feed(cat, fish)
    master.feed(dog, bone)
    # master.feed_cat(cat, fish)
    # master.feed_dog(dog, bone)

    print('-----------------------------------------------')
    # animal:Animal = Cat('white', 'cat1')
    animal: Animal = Dog('black', 'dog1')
    animal.hoot()
